import React,{useEffect} from 'react';
import { Space, Table, Tag,Button,Input,Select    } from 'antd';
import "./user.css";
import { useState } from 'react';
import { SearchOutlined } from '@ant-design/icons';



const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    render: (text) => <p>{text}</p>,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    render: (_, { tags }) => (
      <>
        {tags.map((tag) => {
          let color = tag.length > 5 ? 'geekblue' : 'green';
          if (tag === 'loser') {
            color = 'volcano';
          }
          return (
            <Tag color={color} key={tag}>
              {tag.toUpperCase()}
            </Tag>
          );
        })}
      </>
    ),
  },
  {
    title: 'Action',
    key: 'action',
    render: (_, record) => (
      <Space size="middle">

        <Button type="primary">edit</Button>
        <Button type="primary" danger>Delete</Button>
        
      </Space>
    ),
  },
];
const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sydney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
];

const keywordOption = [
  {
    value: 'name',
    label: 'name',
  },
  {
    value: 'id',
    label: 'id',
  }
]

const listParams = {
  page:1,
  pageSize:15,
  status:"",
  keyword:"",
  keywordType:""
}
const seletorOption = [
  {
    value: 'name',
    label: 'Jack',
  },
  {
    value: 'lucy',
    label: 'Lucy',
  }
]


const UserIndex = () => {


  const [keyword, setKeyword] = useState('');
  const [keywordType, setKeywordType] = useState('');

  
  useEffect(()=>{
    getListData();
  },[])

  const getListData = ()=>{
    console.log(listParams);
  }
  const handleChange = (value) => {
    listParams.status = value;
    listParams.page = 1;
    getListData();
  };
  const onKeywordSearch = ()=>{
    listParams.page = 1;
    listParams.keyword = keyword;
    getListData()
  }
  const changeSearchOption = (val)=>{
    listParams.keywordType = val;
  }

  

    return (
        <>

        <div className='table-header'>

          <div >


            <Select
                style={{
                  width: 120,
                }}
                placeholder="Select"
                onChange={handleChange}
                options={seletorOption}
            />


          </div>

          <Space.Compact style={{ width: '300px'}} >
                <Select placeholder="type" options={keywordOption}   onChange={changeSearchOption} />
                <Input  placeholder='search keyword'   value={keyword} onChange={e => setKeyword(e.target.value)}   />
                <Button type="primary" onClick={onKeywordSearch}><SearchOutlined /></Button>
          </Space.Compact>

        </div>



        <Table columns={columns} dataSource={data} />


        </>
    )
};
export default UserIndex;